﻿using System;

namespace HslCommunication.Core.Address
{
	/// <summary>
	/// 横河PLC的地址表示类<br />
	/// Yokogawa PLC address display class
	/// </summary>
	// Token: 0x0200016C RID: 364
	public class YokogawaLinkAddress : DeviceAddressDataBase
	{
		/// <summary>
		/// 获取或设置等待读取的数据的代码<br />
		/// Get or set the code of the data waiting to be read
		/// </summary>
		// Token: 0x1700061E RID: 1566
		// (get) Token: 0x06001E04 RID: 7684 RVA: 0x0008FF98 File Offset: 0x0008E198
		// (set) Token: 0x06001E05 RID: 7685 RVA: 0x0008FFA0 File Offset: 0x0008E1A0
		public int DataCode { get; set; }

		/// <summary>
		/// 获取当前横河PLC的地址的二进制表述方式<br />
		/// Obtain the binary representation of the current Yokogawa PLC address
		/// </summary>
		/// <returns>二进制数据信息</returns>
		// Token: 0x06001E06 RID: 7686 RVA: 0x0008FFAC File Offset: 0x0008E1AC
		public byte[] GetAddressBinaryContent()
		{
			return new byte[]
			{
				BitConverter.GetBytes(this.DataCode)[1],
				BitConverter.GetBytes(this.DataCode)[0],
				BitConverter.GetBytes(base.AddressStart)[3],
				BitConverter.GetBytes(base.AddressStart)[2],
				BitConverter.GetBytes(base.AddressStart)[1],
				BitConverter.GetBytes(base.AddressStart)[0]
			};
		}

		/// <inheritdoc />
		// Token: 0x06001E07 RID: 7687 RVA: 0x00090028 File Offset: 0x0008E228
		public override void Parse(string address, ushort length)
		{
			OperateResult<YokogawaLinkAddress> operateResult = YokogawaLinkAddress.ParseFrom(address, length);
			bool isSuccess = operateResult.IsSuccess;
			if (isSuccess)
			{
				base.AddressStart = operateResult.Content.AddressStart;
				base.Length = operateResult.Content.Length;
				this.DataCode = operateResult.Content.DataCode;
			}
		}

		/// <summary>
		/// 从普通的PLC的地址转换为HSL标准的地址信息
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <returns>是否成功的地址结果</returns>
		// Token: 0x06001E08 RID: 7688 RVA: 0x00090080 File Offset: 0x0008E280
		public static OperateResult<YokogawaLinkAddress> ParseFrom(string address, ushort length)
		{
			OperateResult<YokogawaLinkAddress> result;
			try
			{
				bool flag = address.StartsWith("CN") || address.StartsWith("cn");
				int dataCode;
				int addressStart;
				if (flag)
				{
					dataCode = 49;
					addressStart = int.Parse(address.Substring(2));
				}
				else
				{
					bool flag2 = address.StartsWith("TN") || address.StartsWith("tn");
					if (flag2)
					{
						dataCode = 33;
						addressStart = int.Parse(address.Substring(2));
					}
					else
					{
						bool flag3 = address.StartsWith("X") || address.StartsWith("x");
						if (flag3)
						{
							dataCode = 24;
							addressStart = int.Parse(address.Substring(1));
						}
						else
						{
							bool flag4 = address.StartsWith("Y") || address.StartsWith("y");
							if (flag4)
							{
								dataCode = 25;
								addressStart = int.Parse(address.Substring(1));
							}
							else
							{
								bool flag5 = address.StartsWith("I") || address.StartsWith("i");
								if (flag5)
								{
									dataCode = 9;
									addressStart = int.Parse(address.Substring(1));
								}
								else
								{
									bool flag6 = address.StartsWith("E") || address.StartsWith("e");
									if (flag6)
									{
										dataCode = 5;
										addressStart = int.Parse(address.Substring(1));
									}
									else
									{
										bool flag7 = address.StartsWith("M") || address.StartsWith("m");
										if (flag7)
										{
											dataCode = 13;
											addressStart = int.Parse(address.Substring(1));
										}
										else
										{
											bool flag8 = address.StartsWith("T") || address.StartsWith("t");
											if (flag8)
											{
												dataCode = 20;
												addressStart = int.Parse(address.Substring(1));
											}
											else
											{
												bool flag9 = address.StartsWith("C") || address.StartsWith("c");
												if (flag9)
												{
													dataCode = 3;
													addressStart = int.Parse(address.Substring(1));
												}
												else
												{
													bool flag10 = address.StartsWith("L") || address.StartsWith("l");
													if (flag10)
													{
														dataCode = 12;
														addressStart = int.Parse(address.Substring(1));
													}
													else
													{
														bool flag11 = address.StartsWith("D") || address.StartsWith("d");
														if (flag11)
														{
															dataCode = 4;
															addressStart = int.Parse(address.Substring(1));
														}
														else
														{
															bool flag12 = address.StartsWith("B") || address.StartsWith("b");
															if (flag12)
															{
																dataCode = 2;
																addressStart = int.Parse(address.Substring(1));
															}
															else
															{
																bool flag13 = address.StartsWith("F") || address.StartsWith("f");
																if (flag13)
																{
																	dataCode = 6;
																	addressStart = int.Parse(address.Substring(1));
																}
																else
																{
																	bool flag14 = address.StartsWith("R") || address.StartsWith("r");
																	if (flag14)
																	{
																		dataCode = 18;
																		addressStart = int.Parse(address.Substring(1));
																	}
																	else
																	{
																		bool flag15 = address.StartsWith("V") || address.StartsWith("v");
																		if (flag15)
																		{
																			dataCode = 22;
																			addressStart = int.Parse(address.Substring(1));
																		}
																		else
																		{
																			bool flag16 = address.StartsWith("Z") || address.StartsWith("z");
																			if (flag16)
																			{
																				dataCode = 26;
																				addressStart = int.Parse(address.Substring(1));
																			}
																			else
																			{
																				bool flag17 = address.StartsWith("W") || address.StartsWith("w");
																				if (!flag17)
																				{
																					throw new Exception(StringResources.Language.NotSupportedDataType);
																				}
																				dataCode = 23;
																				addressStart = int.Parse(address.Substring(1));
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
				result = OperateResult.CreateSuccessResult<YokogawaLinkAddress>(new YokogawaLinkAddress
				{
					DataCode = dataCode,
					AddressStart = addressStart,
					Length = length
				});
			}
			catch (Exception ex)
			{
				result = new OperateResult<YokogawaLinkAddress>(ex.Message);
			}
			return result;
		}
	}
}
